$('.right-titleicon').on("click",function(e){
	projectVM.showMenulist()
})
			
		let that;
		projectVM = new Vue({
			el: "#content",
			data: {
				onStatus:false,
				showMenu:false,
				onlyselect:false,
				mDisable:false,
				checked:[],
				menuList:[
					{name:'投入',path:'goIn.html'},{name:'退出',path:'goOut.html'},{name:'列表',path:'index.html'},
				],
				filterText:'all', //筛选条件
				list:[{
						isLumpFirst:false,
						isLumpFirstAdd:true,
						deviceCode:"",//设备编号
						deviceName:"",//设备名称
						outTime:"",//退出时间
						stopTime:"",//停机间隔
						remark:"",//区调/中调令
						day:"",
						hour:"",
						minute:"",
						monthOutCount:"",//本月此装置退出次数(累计值)
					}],
			exitDataJson:"",//编辑用的数据
			},
			created: function() {
				that = this;
				that.list[0].outTime = that.dateFormate()
				setTimeout(that.getDetail,500);
			},
			components:{
				selectitem
			},
			methods: {
				
				//验证设备编号
				getDevideCode(str){

				},
				setCode(){
					that.list.forEach((its,i)=>{
						let a = that.$refs;
						let GV = 'selectitem'+i
						let chooseData = that.$refs[GV][0].chooseItem;
						that.$nextTick(that.$refs[GV][0].formInline.member = its.deviceCode)
					})
				},
				itemChange(position){
					let GV = 'selectitem'+position
					let chooseData = this.$refs[GV][0].chooseItem;
					
					
					let mTime = that.GetNumberOfDays(chooseData.inTime);
					
					that.list[position].deviceName = chooseData.deviceName;
					that.list[position].deviceCode = chooseData.deviceCode;
					that.list[position].monthOutCount = chooseData.monthOutCount;
					that.list[position].day = mTime.day;
					that.list[position].hour = mTime.hour;
					that.list[position].minute = mTime.mm;
				},
				//获取相减之后的时间
				GetNumberOfDays(date){//获得天数
					let thisTime = that.dateFormate()
				    //date1：开始日期，date2结束日期
				    var a1 = Date.parse(new Date(date));
				    var a2 = Date.parse(new Date(thisTime));
					
					var num = (a2 - a1)/(60 * 60 * 1000);
					let mNum = Math.floor(num * 100) / 100//总的小时数
					
					let day = mNum/24;//总天数
					let mDay = parseInt(day)//整数天
					
					let hour = (day - mDay) * 24;//还剩的总的小时数
					let mHour= parseInt(hour);//整小时数
					
					let mm = (hour - mHour) * 60
					let mMm = parseInt(mm)

					let timeObj= {}
					timeObj.day = mDay;
					timeObj.hour = mHour;
					timeObj.mm = mMm;
					
				    // var day = parseInt((a2-a1)/ (1000 * 60 * 60 * 24));//核心：时间戳相减，然后除以天数
				    return timeObj
				},
				getDetail(){
					let config = mui.neioConfig.getNeioConfig();
					let url = config.URL.queryNetDeviceInfoById;
					//详情数据的Key
					let key = config.KEYS.DEVOICE;
					let mData = mui.neioConfig.getStorage(key);
					if("" == mData || undefined == mData){
						return;
					}
					let data = JSON.parse(mData);
					let param = {};
					param.outOperateId = data.outOperateId;//退出设备ID
					param.deviceCode = data.deviceCode;//设备编码
					//清空 缓存
					mui.neioConfig.setStorage(key,"");
					mui.neiosRequst.httpRequst(url,param,function(ret){
						if(ret.code == 0){
							mui.toast(ret.msg)
							//数据暂存
							let　dataParam = {};
							dataParam.netDeviceOperate = ret.operate;
							dataParam.netDeviceInfo = ret.data;
							that.exitDataJson = dataParam;
							let array = [];
							ret.data.forEach((item,i)=>{
								let detailData;
								if(array.length == 0){
									detailData = {
										isLumpFirst:false,
										isLumpFirstAdd:true,
									};	
								}else{
									detailData = {
										isLumpFirst:true,
										isLumpFirstAdd:true,
									};	
								}
								detailData.deviceCode = item.deviceCode;
								detailData.deviceName = item.deviceName
								detailData.outTime = item.outTime;
								detailData.stopTime = item.stopTime;
								detailData.remark = item.remark;
								detailData.day = item.stopTime.split('天')[0];
								detailData.hour = item.stopTime.split('天')[1].split('时')[0];
								detailData.minute = item.stopTime.split('天')[1].split('时')[1].split('分')[0];

								detailData.monthOutCount = item.monthOutCount;
								detailData.deviceInfoId = item.deviceInfoId;
								let position = array.length+1;
								array.push(detailData);
							})
							that.list = array;
							setTimeout(that.setCode, 500);
							//数据展示
						}
						if( ret.code == 1){
							mui.toast(ret.msg)
						}
					},function(err){
						console.log("失败回掉："+JSON.stringify(err))
					})
				},
				
				showTime(position){
				  var dtpicker = new mui.DtPicker({ 
					  "type": "datetime"
				  })
				  dtpicker.show(function(e) { 
					  let outTime = e.value;
					  that.list[position].outTime = outTime;
				  })
				},
				//获取 UUID
				uuidv4() {
					let uuid = mui.neiosCommon.getUuidv4();
					return uuid;
				},
				
				//编辑上传数据
				exitData(){
					//主数据
					let param = {};
					param.netDeviceOperate = {};
					param.netDeviceInfo = [];
					let persionData = JSON.parse(localStorage.getItem("neiosUser"));
					param.netDeviceOperate.networkDeviceOperateId = that.uuidv4();//主键
					param.netDeviceOperate.workId = "";// that.uuidv4();//保存没有
					param.netDeviceOperate.workDesc = "";//保存没有 - 对涉网设备的投入信息进行提交
					param.netDeviceOperate.areaCompanyCode = persionData.companyCode;//分公司code
					param.netDeviceOperate.newAreaCode = persionData.companyNewCode;//新能源分公司code
					param.netDeviceOperate.stationCode =  persionData.stationCode;//localStorage.getItem('neiosStationCode');//场站code
					param.netDeviceOperate.newStationCode = localStorage.getItem('neiosStationCode');//新能源场站code
					param.netDeviceOperate.operateStaffCode = persionData.userId;//当前登陆人ID
					param.netDeviceOperate.operateStaffName = persionData.name;//当前登陆人Name
					param.netDeviceOperate.operateType = "1";//1代表投入 固定值
					param.netDeviceOperate.operateTime = "";// <<例子里没传>>
					param.netDeviceOperate.remark = "";// <<例子里没传>>
					param.netDeviceOperate.client = "NEIOS";//固定值
					param.netDeviceOperate.dataSource = "NEIOS_APP"+localStorage.getItem("currVersion");
					param.netDeviceOperate.status = "32";//提交 32 保存 21
					param.netDeviceOperate.dataStatus = "1";//固定值 1 有效 0 无效
					param.netDeviceOperate.createBy = persionData.userId;//创建人Id
					param.netDeviceOperate.createStaffName = persionData.name;//创建人姓名
					param.netDeviceOperate.createDate = "";//创建时间
					param.netDeviceOperate.modifyBy = persionData.userId;//当前登陆人工号
					param.netDeviceOperate.modifyStaffName = persionData.name;//当前登陆人姓名
					param.netDeviceOperate.modifyDate = "";//修改时间
					
					let userInfor = {};
					userInfor.userId = persionData.userId;
					userInfor.name = persionData.name;
					param.currentUser = userInfor;
					
					let data = that.childDataCreate(param);
					param.netDeviceInfo = data;
					return param;
					
				},
				//编辑子表数据
				childDataCreate(param){
					let mList = that.list;
					mList.forEach((childData,i) =>{
						childData.addif = true;
						childData.delif = false;
						childData.outTime = that.dateFormate();//存入时间
						childData.showTree = false;

						childData.deviceInfoId = param.netDeviceInfo[i] == undefined ? that.uuidv4() : param.netDeviceInfo[i].deviceInfoId;

						childData.outOperateId = param.netDeviceOperate.networkDeviceOperateId;
						childData.areaCompanyCode = param.netDeviceOperate.areaCompanyCode;
						childData.stationCode = param.netDeviceOperate.stationCode;
						childData.newAreaCode = param.netDeviceOperate.newAreaCode;
						childData.newStationCode = localStorage.getItem('neiosStationCode');
						childData.status = "32";
						childData.dataStatus = "1";
						childData.stopTime = childData.day+'天'+childData.hour+'时'+childData.minute+'分';
						childData.dataSource = param.netDeviceOperate.dataSource;
						childData.client = "NEIOS";
						childData.createBy = param.netDeviceOperate.createBy;
						childData.createStaffName = param.netDeviceOperate.createStaffName;
						childData.modifyBy = param.netDeviceOperate.modifyBy;
						childData.modifyStaffName = param.netDeviceOperate.modifyStaffName;
					})
					
					return mList;
					// that.doPhsu(param);
				},
				
				//保存数据
				saveData(params){
					let param = params;
					if(that.exitDataJson != ""){
						let child  = that.childDataCreate(that.exitDataJson)
						that.exitDataJson.netDeviceInfo = child;
						param = that.exitDataJson;
					}
					param.netDeviceOperate.workId = "";
					param.netDeviceOperate.workDesc = "";
					param.netDeviceOperate.status = "21";
					param.netDeviceInfo.forEach((item,position) =>{
						item.status = "21"
					})
					return param;
				},
				//提交数据
				commitData(params){
					let param = params;
					if(that.exitDataJson != ""){
						let child  = that.childDataCreate(that.exitDataJson)
						that.exitDataJson.netDeviceInfo = child;
						param = that.exitDataJson;
					}
					param.netDeviceOperate.workId = that.uuidv4();
					param.netDeviceOperate.workDesc = "对涉网设备的投入信息进行提交";
					param.netDeviceOperate.status = "32";
					param.netDeviceInfo.forEach((item,position) =>{
						item.status = "32"
					})
					param.workType = "0204";
					return param;
				},
				
				//进行提交操作
				/**
				 * @param {Object} type 类型 32 提交 21 保存
				 */
				doPhsu(type){
					let message = type == "21" ? "是否保存" : "是否提交";
					mui.confirm(message,'提示',['取消','确认'],function (e) {
						if(1 == e.index){
							that.list.forEach((item,i)=>{
								// if(that.list[i].deviceCode == ""){
									let GV = 'selectitem'+i
									item.deviceCode = that.$refs[GV][0].formInline.member;
								// }
							})
							let param = {};
							if('32' == type){
								if(that.exitDataJson != ""){
									param = that.commitData(that.exitDataJson);
								}else{
									param = that.commitData(that.exitData());
								}
							}
							if("21" == type){
								if(that.exitDataJson != ""){
									param = that.saveData(that.exitDataJson);
								}else{
									param = that.saveData(that.exitData());
								}
							}
							var checkData = param.netDeviceInfo;
							mui.neioConfig.setNetData(param.netDeviceInfo,"out",function(fun,newData){
								param.netDeviceInfo = newData;
								let isNuLL = mui.neioConfig.checkNetWorkList(param.netDeviceInfo,"out")
								if(!isNuLL) return
								let config = mui.neioConfig.getNeioConfig();
								let url = config.URL.saveOrUpdateNetDevice;
								param.workType = "0209";
								mui.neiosRequst.httpRequst(url,param,function(ret){
									if(ret.code == 0){
										mui.toast(ret.msg)
										that.goBack()
									}
									if( ret.code == 1){
										mui.toast(ret.msg)
									}
								},function(err){
									console.log("失败回掉："+JSON.stringify(err))
								})
							});
						}
					},'div')
								
				},
				
				// 获取时间
				dateFormate () {
					return mui.neiosCommon.transTime(new Date(),"min")
				},
				//获取毫秒
				getMiu(){
					let date = that.dateFormate();
					var arr = date.split(/[- : \/]/);
					var startDate = Date.parse(new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4]));
					return startDate;
				},
				//检查时间是否为 23
				checkTime(timeStr,position,rage){
					let time = parseInt(timeStr)
					
						if(rage == 'minute'){
							if(time > 59){
								that.list[position].minute = "";
								alert("当前数值不能大于59")
							}
							return
						}
						if(rage == 'hour'){
							if(time > 23){
								that.list[position].hour = "";
								alert("当前数值不能大于23")
							}
							return
						}
				},
				
				goBack(){
					let pageId = plus.webview.getWebviewById("dailyRecord/network/index.html");
					mui.fire(pageId, 'ttTT', {result:"result"});
					mui.back()
				},
				//全选
				chooseAll(e){
					if(this.checked.length == this.list.length){
						this.checked = []
					}
					else{
					var arr = []
					this.list.forEach((e,index) => {
						arr.push(index)
					});
					this.checked = arr
					}
				},
				//跳转页面
				navTo(e){
					mui.openWindow({
            			url: e,
            			id: e,
						extras: {},
					waiting: {
					autoShow: false
					}
        			});
				},
				//点击菜单
				menuClick(e){
					if(e.name == '我值班'){
						this.onStatus? this.onStatus= false : this.onStatus=true
					}
					else{
						this.navTo(e.path)
					}
				},
				//左上角菜单显示隐藏
				showMenulist(){
					this.showMenu?this.showMenu=false:this.showMenu=true
				},
				//切换筛选条件
				changeFliter(e){
					this.filterText = e
				},
				//添加新的检查单
				addLupm(){
					this.list.forEach( (item,i) =>{
						if(i == 0){
							item.isLumpFirst = true;
							item.isLumpFirstAdd = false;
						}
					})
					let newLumpItem = {
						isLumpFirst:true,
						isLumpFirstAdd:true,
						deviceCode:"",//设备编号
						deviceName:"",//设备名称
						outTime:"",//退出时间
						stopTime:"",//停机间隔
						remark:"",//区调/中调令
						day:"",
						hour:"",
						minute:"",
						monthOutCount:"",//本月此装置退出次数(累计值)
					}
					this.list.push(newLumpItem)
				},
				//移除检查单
				removeLupm(position){
					//移除页面传过来的对应的 item
					if(that.exitDataJson != ""){
						that.exitDataJson.netDeviceInfo.forEach((item,i)=>{
							if(item.deviceInfoId == this.list[position].deviceInfoId){
								that.exitDataJson.netDeviceInfo.splice(i,1);
							}
						})
					}
					
					this.list.splice(position,1)
					if(this.list.length <= 1){
						this.list[0].isLumpFirst = false;
						this.list[0].isLumpFirstAdd = true;
					}else{
						let lumpItemPosition = this.list.length;
						this.list[lumpItemPosition - 1].isLumpFirstAdd = true;
					}
				},
				navTo(e){
					mui.openWindow({
            			url: e,
            			id: e,
					});
				}
				},
			
			})
			var page = 0
		

			mui.init({
				pullRefresh: {
				  container: "#scroll", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
				  down: { //下拉刷新
					style: 'circle',
					height: 50, //可选,默认50.触发下拉刷新拖动距离,
					auto: false, //可选,默认false.首次加载自动下拉刷新一次
					contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
					contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
					contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
					callback: async function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					  page = 0;
					  
					  ////没有更多内容了，endPulldown 传入true， 不再执行下拉刷新
				  mui('#scroll').pullRefresh().endPulldownToRefresh();
					  mui('#scroll').pullRefresh().enablePullupToRefresh();
					mui('#scroll').pullRefresh().endPullupToRefresh(true); 
					   }
				  },
				  up: { //上拉加载
					height: 50, //可选.默认50.触发上拉加载拖动距离
					auto: false, //可选,默认false.自动上拉加载一次
					contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
					contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
					callback: async function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					  
					}
				  }
				}
			  });